package com.restaurant.application.minifacade.data;

import com.google.common.collect.Lists;
import com.nebutown.generation.Convert;
import com.nebutown.generation.PickableBean;

import java.util.List;
import java.util.stream.Collectors;

public class CardListBO implements PickableBean {

    public static final String FN_LISTS = "lists";

    public static final List<String> FIELD_NAMES = Lists.newArrayList(
            FN_LISTS);

    private List<CardBO> lists;

    public CardListBO(List<CardBO> lists) {
        setLists(lists);
    }

    public CardListBO() {
    }

    public CardListBO duplicate() {
        CardListBO result = new CardListBO();
        result.lists = this.lists == null ? null : this.lists.stream().map(e1 -> e1 == null ? null : e1.duplicate()).collect(Collectors.toList());
        return result;
    }

    @Override
    public String toString() {
        return Convert.toJson(this);
    }

    public List<CardBO> getLists() {
        if (lists == null) {
            lists = Lists.newArrayList();
        }
        return lists;
    }

    public void setLists(List<CardBO> value) {
        this.lists = value;
    }

    public CardListBO withLists(List<CardBO> value) {
        setLists(value);
        return this;
    }

    public CardListBO withLists(List<CardBO> value, List<CardBO> defaultValue) {
        setLists(value == null ? defaultValue : value);
        return this;
    }

    public CardListBO addLists(CardBO value) {
        if (lists == null) {
            lists = Lists.newArrayList();
        }
        this.lists.add(value);
        return this;
    }

    public Object getValueOf(String name) {
        switch (name) {
            case "lists":
                return getLists();
        }
        return null;
    }

    public boolean hasField(String name) {
        return FIELD_NAMES.contains(name);
    }

    @Override
    public int hashCode() {
        return signature().hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof CardListBO)) return false;
        return signature().equals(((CardListBO) o).signature());
    }

    public String signature() {
        throw new RuntimeException("Bean CardListBO has no signature defined, no hash code or equals possible.");
    }
}
